<?php
/********************************************************
** Copyright 2010-2013. Todos los derechos reservados. **
** Desarrollado y Gestionado por:					   **
** Sugey Quintero (Analista)						   **
** José G. De Freitas (Programador)					   **
** Klaudia Uribe (Diseñadora Web)					   **
** Cesar Isturiz (Diseñador Web)					   **
**				S E A  v1.0							   **
*********************************************************/

session_start();
include("conexion.php");

	if (isset($_SESSION['name']) and isset($_SESSION['tiempo'])) {
        include("Tiempo.php");
	date_default_timezone_set('America/Caracas'); setlocale(LC_TIME, 'spanish');
	$usuario = $_SESSION['name'];
	$fecha = date("Y-m-d H:i:s");
	$auditoria = mysql_query("INSERT INTO auditoria SELECT '$usuario', '$fecha' , 'Listado de Representantes' ");

    }else {
		echo "<script>alert('Debe ingresar al sistema primero');</script>";
		echo "<script>document.location.href='index.php';</script>";
	}

$Periodo=$_GET['Periodo'];
$Grado=$_GET['Grado'];
$Seccion=$_GET['Seccion'];
if ($Grado && $Seccion && $Periodo){
	$sql = mysql_query("SELECT Cedula, Nombres, Apellido, Direccion, T_casa, T_movil FROM representante WHERE representante.Cedula IN (SELECT Cedula_r FROM estudiante_representante WHERE Cedula_e IN (SELECT Cedula_e FROM inscripcion WHERE Periodo='$Periodo' AND Grado='$Grado' AND Seccion='$Seccion'))");
}

$a=mysql_fetch_array(mysql_query("SELECT COUNT(DISTINCT(Cedula)) FROM representante WHERE Cedula IN (SELECT Cedula_r FROM estudiante_representante WHERE Cedula_e IN (SELECT Cedula_e FROM inscripcion WHERE Periodo='$Periodo' AND Grado='$Grado' AND Seccion='$Seccion'))"));
$b=mysql_fetch_array(mysql_query("SELECT COUNT(DISTINCT(Cedula_e)) FROM estudiante WHERE Cedula_e IN (SELECT Cedula_e FROM inscripcion WHERE Periodo='$Periodo' AND Grado='$Grado' AND Seccion='$Seccion')"));


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Listados Representantes</title>
<link rel="shortcut icon" type="image/x-icon" href="../favicon.ico">
<link href="style.css" rel="stylesheet" type="text/css" />
<!-- calendario-->
<link rel="stylesheet" type="text/css" href="src/css/jscal2.css" />
<link rel="stylesheet" type="text/css" href="src/css/border-radius.css" />
<link rel="stylesheet" type="text/css" href="src/css/steel/steel.css" />
<script type="text/javascript" src="src/js/jscal2.js"></script>
<script type="text/javascript" src="src/js/lang/es.js"></script>
<!-- fin calendario-->
<!-- botones-->
<link type="text/css" href="js/css/smoothness/jquery-ui-1.8.16.custom.css" rel="Stylesheet" />      
<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script> 
<script>
var j$ = jQuery.noConflict();
j$(document).ready(function(){
j$(".button").button();
});

j$(function(){
	j$('#menu li a').click(function(event){
		var elem = j$(this).next();
		if(elem.is('ul')){
			event.preventDefault();
			j$('#menu ul:visible').not(elem).slideUp();
			elem.slideToggle();
		}
	});
});
</script>
<!-- fin botones-->
</head>

<body>
<div id="wrap">
<div id="header">
<div id="hora">
<?php include("Hora.php"); ?>
</div>
<div id="topnav">
	<?php include("MenuSuperior.php"); ?>
</div>
</div>
<div id="content">
<div id="left">
<div class="post">
<div class="post_h">

</div>

<div class="postcontent">

<blockquote><h2 align="center">LISTADO REPRESENTANTES</h2></blockquote>
			<form action="ListadoRepresentantes.php" method="GET">
			<fieldset>
			<legend align=left><b><font size=2>BUSCADOR</font></b></legend>
			<table width=100% cellspacing=5 cellpadding=0 border=0>
			<tr>
			<td align=center><select name="Grado"><option>Grado</option>
												<option <?php if ($Grado=='Primer'){ echo "Selected"; } ?>>Primer</option>
												<option <?php if ($Grado=='Segundo'){ echo "Selected"; } ?>>Segundo</option>
												<option <?php if ($Grado=='Tercer'){ echo "Selected"; } ?>>Tercer</option>
												<option <?php if ($Grado=='Cuarto'){ echo "Selected"; } ?>>Cuarto</option>
												<option <?php if ($Grado=='Quinto'){ echo "Selected"; } ?>>Quinto</option>
												<option <?php if ($Grado=='Sexto'){ echo "Selected"; } ?>>Sexto</option></select>
											<select name="Seccion">
												<option>Secci&oacute;n</option>
												<option <?php if ($Seccion=='A'){ echo "Selected"; } ?>>A</option>
												<option <?php if ($Seccion=='B'){ echo "Selected"; } ?>>B</option>
												<option <?php if ($Seccion=='C'){ echo "Selected"; } ?>>C</option>
												<option <?php if ($Seccion=='D'){ echo "Selected"; } ?>>D</option>
												<option <?php if ($Seccion=='E'){ echo "Selected"; } ?>>E</option></select>
								<select name="Periodo"><option>Periodo</option><option><?php $anio=2000; $anio2=$anio+1; while($anio<date(Y)+1){ echo "<option "; if ($Periodo=="$anio - $anio2"){ echo "Selected"; } echo "> $anio - $anio2 </option>"; $anio++; $anio2++; } ?></option></select>
								<input class=button type=submit value=Buscar></td>
			</tr>
			</table>
			</fieldset>
			</form>

<div class="post">
<span></span></div>

		<?php if($sql){
			echo "<fieldset>";
			echo "<legend align=left><b><font size=2>REPRESENTANTES DE ".strtoupper($Grado)." GRADO $Seccion Periodo $Periodo</font></b></legend>";
			echo "<table width=100%  cellspacing=0 cellpadding=0 border=0 style='border-collapse: collapse;'>";
			echo "<tr><td><br></td></tr>";
			echo "<tr>";
			echo "<th>REPRESENTANTE</th><th>DIRECCION</th><th>TELEFONOS</th><th>ESTUDIANTE</th>";
			echo "</tr>";
			echo "<tr><td><br></td></tr>";
				while($row=mysql_fetch_array($sql)){
					$estudiante=mysql_query("SELECT Nombres, Apellidos FROM estudiante WHERE Cedula_e IN (SELECT Cedula_e FROM estudiante_representante WHERE Cedula_r='$row[0]' AND Cedula_e IN (SELECT Cedula_e FROM inscripcion WHERE Periodo='$Periodo' AND Grado='$Grado' AND Seccion='$Seccion'))");
					while($row2=mysql_fetch_array($estudiante)){
						echo "<tr align=center style='border-bottom:1px solid #006699;'>";
						echo "<td>$row[1]<br>$row[2]</td><td>$row[3]</td><td>$row[4]<br>$row[5]</td><td><a href='BuscadorEstudiante.php?Nombres=$row2[0]&Apellidos=$row2[1]' title='Click aqui para visualizar o actualizar los datos del estudiante'>$row2[0]<br>$row2[1]</a></td>";
						echo "</tr>";
						echo "<tr><td><br></td></tr>";
					}
				}
			echo "<tr><td><br></td></tr>";
			echo "<tr><th colspan=4>CANTIDAD DE REPRESENTANTES $a[0] Y DE ALUMNOS $b[0]</th></tr>";
			echo "</table>";
			echo "</fieldset>";
			echo "<div class='post'>";
			echo "<span></span></div>";
			echo "<div name=botonera align=center>";
			echo "<input type=hidden name=Periodo value='$Periodo'>";
			echo "<input type=hidden name=Grado value=$Grado>";
			echo "<input type=hidden name=Seccion value=$Seccion>";
			echo "<a class='button' href='PdfListadoRepresentantes.php?Periodo=$Periodo&Grado=$Grado&Seccion=$Seccion' target='_blank'>Generar PDF</a><input class=button type=button value=Volver onClick=\"location='index.php'\">";
			echo "</div>";
		} ?>

<div align=right><a title='Ayuda' href="Manuales/ManualUsuario_6.3.pdf" onclick="window.open(this.href,'Manual','params'); return false"><img src='images/help.png' width=8% height=15%></a></div>

</div>
<div class="post_b">
<span></span></div>
</div>


</div>

<div class="post">
<div class="post_h">

</div>


</div>

<?php include("Menu.php"); ?>

<div class="clear"></div>
</div>
<div id="pagebottom"></div>

<div id="footer">
<P>&reg; Derechos Reservados @ CopyRight. 2011-2012</P>
<p>Programadores: Quintero E, Isturiz C, Uribe C, De Freitas J.</p>
</div>
</div>
</body>
</html>
